home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / STUTTGART / DEMOS / SWARS / !Swars / Sources / c / !RunImage2 < prev   
Text File  |  1996-03-17  |  5KB  |  209 lines

  1. /*******************************************************/
  2. /* -=[FlY'96]=- StarWars scroller (no vertical deform) */
  3. /*******************************************************/
  4.  
  5. /* includes */
  6.  
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <kernel.h>
  10. #include <swis.h>
  11. #include <math.h>
  12. #include "Swarshead.h"
  13.  
  14. #ifdef C4
  15. #include "bbc.h"
  16. #endif
  17.  
  18. #define C5
  19.  
  20. /* Global variables */
  21.  
  22. screen scr;
  23.  
  24. /* MAIN --------------------------------------- */
  25.  
  26. int main (void)
  27. {
  28.   /* variables used */
  29.   FILE *in;
  30.   int   i;
  31.  
  32.   _kernel_swi_regs reg;
  33.   _kernel_oserror *err;
  34.   int block[8];
  35.   char char_buffer[8];
  36.   unsigned char *buf;
  37.   unsigned char *imgd;
  38.   unsigned int   s[SCRLENGTH];
  39.   scrobj p[SCRLENGTH];
  40.  
  41.   scr.mode = GFXMODE;
  42.  
  43. #ifdef C4
  44.   bbc_mode(scr.mode);
  45. #endif
  46.  
  47. #ifdef C5
  48.    char_buffer[0] = 22;
  49.    char_buffer[1] = scr.mode;
  50.  
  51.    reg.r[0] = (int)char_buffer;
  52.    reg.r[1] = 2;
  53.    if((err=_kernel_swi(OS_WriteN, ®, ®)) != NULL) {
  54.      fprintf(stderr,"OS_WriteN error : %s\n", err->errmess);
  55.      exit(EXIT_FAILURE);
  56.    }
  57. #endif
  58.  
  59. /* OFF */
  60.    if((err=_kernel_swi(OS_RemoveCursors, ®, ®)) != NULL) {
  61.      fprintf(stderr,"OS_RemoveCursors error : %s\n", err->errmess);
  62.      exit(EXIT_FAILURE);
  63.    }
  64.  
  65.    block[0] = 148;
  66.    block[1] = 149;
  67.    block[2] = 150;
  68.    block[3] = -1;
  69.  
  70.    reg.r[0] = (int)block;
  71.    reg.r[1] = (int)block;
  72.    if((err=_kernel_swi(OS_ReadVduVariables, ®, ®)) != NULL) {
  73.      fprintf(stderr,"OS_ReadVduVariables error : %s\n", err->errmess);
  74.      exit(EXIT_FAILURE);
  75.    }
  76.  
  77.    scr.ScreenStart  = (unsigned char *)block[0];
  78.    scr.DisplayStart = (unsigned char *)block[1];
  79.    scr.TotalScreenSize = (unsigned int)block[2];
  80.  
  81.    if((buf = calloc(SCRSIZE,sizeof(char))) == NULL) {
  82.      fprintf(stderr,"Cannot allocate %u bytes for buffer\n", SCRSIZE*sizeof(char));
  83.      exit(EXIT_FAILURE);
  84.    }
  85.    if((imgd = calloc(SCRSIZE,sizeof(char))) == NULL) {
  86.      fprintf(stderr,"Cannot allocate %u bytes for imgd\n", SCRSIZE*sizeof(char));
  87.      exit(EXIT_FAILURE);
  88.    }
  89. /* load image */
  90.  
  91.    printf("Loading image\n");
  92.    if((in=fopen("<Flyns$Dir>.lenspic","rb")) == NULL) {
  93.       fprintf(stderr,"Cannot open \"swarspic\" for input\n");
  94.       exit(EXIT_FAILURE);
  95.    }
  96.    for (i=0;i<56;i++) buf[i] = fgetc(in); /* skip info bytes */
  97.    for(i=0; i<SCRSIZE; i++)  buf[i] = fgetc(in);
  98.    fclose(in);
  99. /* end load image into buffer */
  100.  
  101. /*-----------------------------------------------------------------------*/
  102.    /* init for the loop */
  103.    printf("Building an object ...\n");
  104.    initobjet(p);
  105.    printf("Initialising the steps ...\n");
  106.    initstep(s,p);
  107.    #ifdef DEBUG
  108.    for(i=SCRLENGTH;i>=LENGTHMAX;i--) printf("%u  %u %u\n",p[i].start,p[i].stop,s[i]);
  109.    #endif
  110.    printf("And now the deformation effect ...\n");
  111.    do
  112.    { /* wait vbl */
  113.      reg.r[0] = 19;
  114.      reg.r[1] = 0;
  115.      if((err=_kernel_swi(OS_Byte, ®, ®)) != NULL) {
  116.      fprintf(stderr,"OS_Byte error : %s\n", err->errmess);
  117.      exit(EXIT_FAILURE);
  118.      }
  119.      /* end wait vbl */
  120.      stretch(buf,imgd,s,p); /* stretch buffer onto the object */
  121.      starwars(imgd);        /* display the stretched image */
  122.      scrolls(buf);          /* scroll the original image one line up */
  123.      _kernel_swi(OS_Mouse, ®,®);
  124.    } while(reg.r[2] == 0);
  125.  
  126.    return(0);
  127. }
  128. /*-----------------------------------------------------------------------*/
  129.  
  130. /*******************************/
  131. /* Functions used in this code */
  132. /*******************************/
  133.  
  134. void initobjet(scrobj *p)
  135. {
  136.   int i;
  137.  
  138.   for (i=SCRLENGTH-1;i>=LENGTHMAX;i--)
  139.   {
  140.     p[i].start=SCRLENGTH-i;
  141.     p[i].stop=SCRWIDTH-2*p[i].start-1;
  142.   }
  143. }
  144. /**************************************************************************/
  145. void initstep(unsigned int *s, scrobj *p)
  146. {
  147.   int  i;
  148.  
  149.   for (i=SCRLENGTH-1;i>=LENGTHMAX;i--)
  150.   {
  151.     s[i]=(SCRWIDTH << 8)/(p[i].stop);
  152.   }
  153. }
  154. /**************************************************************************/
  155. void stretch(unsigned char *buf,unsigned char *imgd,unsigned int *s, scrobj *p)
  156. {
  157.   unsigned int i,j,k,z,stp,stl;
  158.  
  159.   for (i=SCRLENGTH-1;i>=LENGTHMAX;i--)
  160.   {
  161.     stp=s[i];
  162.     stl=0;
  163.     z=(p[i].start % SCRWIDTH) + i*SCRWIDTH;
  164.     k=p[i].stop;
  165.     for(j=0;j<k;j++)
  166.     {
  167.       imgd[z+j]=buf[i*SCRWIDTH+stl];
  168.       stp=s[i]+stp;
  169.       stl=((1 << 8)+stp) >> 8;
  170.     }
  171.   }
  172. }
  173. /**************************************************************************/
  174. void starwars(unsigned char *imgd)
  175. {
  176.   unsigned char *ecran;
  177.   int i;
  178.  
  179.   ecran=scr.DisplayStart;
  180.  
  181.   for (i=0;i<SCRSIZE;i++)
  182.   {
  183.     ecran[i]=imgd[i];
  184.   }
  185. }
  186. /**************************************************************************/
  187. void scrolls(unsigned char *buf)
  188. {
  189.   unsigned char save[SCRWIDTH];
  190.   int i,j;
  191.  
  192.   for (i=0;i<SCRWIDTH;i++)
  193.   {
  194.      save[i]=buf[i];
  195.   }
  196.   for (i=0;i<SCRLENGTH;i++)
  197.   {
  198.     for (j=0;j<SCRWIDTH;j++)
  199.     {
  200.       buf[i*SCRWIDTH+j]=buf[(i+1)*SCRWIDTH+j];
  201.     }
  202.   }
  203.   for (i=0;i<SCRWIDTH;i++)
  204.   {
  205.     buf[(SCRLENGTH-1)*SCRWIDTH+i]=save[i];
  206.   }
  207. }
  208.  
  209.